﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using System.Collections.Generic;
using ClassLibrary.Entity;

public partial class usercontrol_ucIPod : System.Web.UI.UserControl
{

    TblItemsDAO ItemsDAO = new TblItemsDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData("", "", "");
        }
    }
    public void LoadData(string strName, string strCatID, string strOrderby)
    {
        try
        {
            lvIPod.DataSource = ItemsDAO.GetProduct(0, strName, strCatID, 1, 0, 12, "", 3);
            lvIPod.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
    }
    protected void lvIPod_PagePropertiesChanged(object sender, EventArgs e)
    {
        lvIPod.DataBind();
    }

    protected void btnImage_Click(object sender, ImageClickEventArgs e)
    {
        bool flag = false;
        try
        {

            // string id = Request.QueryString["id"];
            //TblItems item = new TblItems();
            //item.ItemID = Convert.ToInt32(((ImageButton)sender).CommandArgument);
            string IdItem = ((ImageButton)sender).CommandArgument;
            ImageButton imagebutton = (ImageButton)sender;

            BasePage.SetShoppingCartSesstion(IdItem + "|0");

            List<TblOrderDetail> arrItems = new List<TblOrderDetail>();
            if (Session[Global.SESSION_CART] != null)
                arrItems = (List<TblOrderDetail>)Session[Global.SESSION_CART];

            int iNoOfItems = 0;
            double dTotalAmount = 0;

            foreach (TblOrderDetail order in arrItems)
            {
                iNoOfItems += order.Quantity;
                dTotalAmount += Convert.ToDouble(order.Quantity) * Convert.ToDouble(order.Price);
            }

          
            //Response.Redirect("Default.aspx");
            // ScriptManager.RegisterClientScriptBlock(frmViewDetail, this.frmViewDetail.GetType(), "ScriptUpdateParents", "UpdateParentsCart('" + iNoOfItems.ToString() + "|" + dTotalAmount.ToString("0,00.##") + "');", true);
            flag = true;
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
        if (flag)
            Response.Redirect("IPod.aspx");
    }
}
